(defun digits(n)
  (loop for i = n then (floor (/ i 10))
       while (> i 0)
       collect (mod i 10)))

(defun same-digits-simple (a b)
  ;;(print (list a b))
  (equal (sort (digits a) #'>) (sort (digits b) #'>)))

(defun same-digits(&rest values)
  (loop for i in (cdr values) 
     when (not (same-digits-simple (car values) i))
     return nil
     finally (return 'T)))

(defun validp (x a)
  (loop for i from 2 to a 
     when (not (same-digits-simple x (* i x))) 
     do (return nil)
     finally (return T)))

(loop for i from 10 to 1000000 when (validp i 6) do (print i))